cmake_minimum_required(VERSION 3.20)
project(wd-main)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

list(APPEND RESOURCE_FILES
    ${CMAKE_SOURCE_DIR}/resource/ElaWidgetTools.qrc
    ${CMAKE_SOURCE_DIR}/resource/wardsense.qrc
)

# qt5_add_resources(RESOURCE_FILES
# # qt_add_resources(RESOURCE_FILES
#     ${CMAKE_SOURCE_DIR}/resource/ElaWidgetTools.qrc
#     # ${CMAKE_SOURCE_DIR}/resource/Font/ElaAwesome.ttf
# )

# qt5_wrap_ui(UI_FILES
#     mainwindow/mainwindow.ui
# )

set(SRC_FOLDERS
    mainwindow

    audio
    controller
    expandablecard
    graphic
    http-server
    login
    patient_information
    player
    profile
    stream_save
    video
)
if(CMAKE_USE_CUDA_WARD_SENSE)
    LIST(APPEND SRC_FOLDERS action-recognition whisper)
endif()
set(INCLUDE ${SRC_FOLDERS} ${ELAWIDGET_INCLUDE_DIR})

set(SOURCE_FILES_TMP "")
set(HEADER_FILES_TMP "")

# we could use aux_source_directory(), `aux_source_directory(. source)`
# which add files according to language currently used

foreach(SRC_FOLDER ${SRC_FOLDERS})
    file(GLOB SOURCE_FILES_TMP CONFIGURE_DEPENDS
        "${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FOLDER}/*.c"
        "${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FOLDER}/*.cpp")
    list(APPEND SOURCE_FILES ${SOURCE_FILES_TMP})

    file(GLOB HEADER_FILES_TMP CONFIGURE_DEPENDS
        "${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FOLDER}/*.h"
        "${CMAKE_CURRENT_SOURCE_DIR}/${SRC_FOLDER}/*.hpp")
    list(APPEND HEADER_FILES ${HEADER_FILES_TMP})
endforeach()

list(APPEND SOURCE_FILES "main.cpp")
message("Source Files: ${SOURCE_FILES}")
message("Header Files: ${HEADER_FILES}")

    # Qt5::Xml
    # Qt5::Multimedia
    # Qt5::MultimediaWidgets
    # Qt5::Widgets
# standalone
add_executable(main ${SOURCE_FILES} ${HEADER_FILES} ${UI_FILES} ${RESOURCE_FILES})
set(WARD_LINK_LIBS
    Qt5::Core
    Qt5::Gui
    Qt5::Widgets
    Qt5::Multimedia
    Qt5::MultimediaWidgets
    Qt5::Concurrent
    elawidget
    ffmpeg
    opencv)
if(CMAKE_USE_CUDA_WARD_SENSE)
list(APPEND WARD_LINK_LIBS onnxruntime whisper)
endif()
target_link_libraries(main PRIVATE ${WARD_LINK_LIBS})
target_include_directories(main PRIVATE ${INCLUDE} ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})

add_custom_target(run COMMAND $<TARGET_FILE:main>)
add_dependencies(run main)
